<template>
	<view>
		<view class="container">
			<view class="list">
				<view class="item" v-for="(item,index) in tableData" :key="index">
					<uni-swipe-action>
						<uni-swipe-action-item>
							<view class="content-box">
								<view class="" style="margin-right: 10px;padding: 10px;" v-bind:id="item.id"
									@click.native="evaluateClick">
									<view class="name">
										<view class="left">产品序号：</view>
										<view class="right">{{ item.productName }}</view>
									</view>
									<view class="user">
										<view class="left">申请人：</view>
										<view class="right">{{ item.userName }}</view>
									</view>
									<view class="time">
										<view class="left">{{ item.createTime }}</view>
										<view class="right">
											<text style="color:red" v-if="item.handleState==0">未处理</text>
											<text style="color:red" v-if="item.handleState==2">处理中</text>
											<text v-if="item.handleState==1">已处理</text>
										</view>
									</view>
								</view>

							</view>
							<template v-slot:right>
								<view class="" style="display: flex;align-items: center;">
									<button type="default"
										style="height: 100%;display: flex;align-items: center;width: 80px;justify-content: center; font-size: 14px;"
										@click="bindClick(4,item.id)">查看</button>
									<button type="primary"
										style="height: 100%;display: flex;align-items: center;width: 80px;justify-content: center;background-color: #007AFF;font-size: 14px;"
										@click="bindClick(1,item.id)" v-if="item.handleState==0&&isAuth ('feedback:confirm')">确认</button>
									<button type="primary"
										style="height: 100%; display: flex;align-items: center;width: 80px;justify-content: center;font-size: 14px;"
										@click="bindClick(2,item.id)" v-if="item.handleState==2&&isAuth ('feedback:handle')">处理</button>
									<button type="warn"
										style="height: 100%;display: flex;align-items: center;width: 80px;justify-content: center;font-size: 14px;" @click="bindClick(3,item.id)" v-if="item.handleState==1&&item.evaluate===''&&isAuth ('feedback:evaluate')">评价</button>
								</view>

							</template>
						</uni-swipe-action-item>
					</uni-swipe-action>


				</view>
			</view>
		</view>
		<uni-fab ref="fab" :pattern="pattern" :horizontal="horizontal" :vertical="vertical" :direction="direction"
			@fabClick="fabClick" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				searchVal: '',
				tableData: [],
				// 每页数据量
				pageSize: 10,
				// 当前页
				pageCurrent: 1,
				// 数据总量
				total: 0,
				loading: false,

				pattern: {
					color: '#7A7E83',
					backgroundColor: '#fff',
					selectedColor: '#007AFF',
					buttonColor: '#007AFF',
					iconColor: '#fff'
				},
				horizontal: 'right',
				vertical: 'bottom',
				direction: 'horizontal',
				options2: [{
						text: '处理',
						style: {
							backgroundColor: '#007aff'
						}
					},
					{
						text: '确认',
						style: {
							backgroundColor: '#007aff'
						}
					},
					{
						text: '评价',
						style: {
							backgroundColor: '#F56C6C'
						}
					}
				]
			}
		},
		onLoad() {
			this.selectedIndexs = []
			this.getData()
			uni.$on("getlist", (data) => {
				this.getData()
			})
		},
		methods: {
			// 分页触发
			change(e) {
				this.$refs.table.clearSelection()
				this.selectedIndexs.length = 0
				this.getData(e.current)
			},
			isAuth (key) {
			  return JSON.parse(uni.getStorageSync('permissions') || '[]').indexOf(key) !== -1 || false
			},
			// 获取数据
			getData() {
				// this.loading = true
				// this.pageCurrent = pageCurrent
				// this.request({
				// 	pageSize: this.pageSize,
				// 	pageCurrent: pageCurrent,
				// 	value: value,
				// 	success: res => {
				// 		// console.log('data', res);
				// 		this.tableData = res.data
				// 		this.total = res.total
				// 		this.loading = false
				// 	}
				// })
				console.log(this.$store.getters.productId)
				this.request({
					'url': '/wx/syn/feedback/list/' + this.$store.getters.productId,
					'method': 'get',
				}).then(res => {
					console.log(res)
					if (res && res.code == 200) {
						this.tableData = res.list
						this.total = res.list.length
					}
				}).catch(err => {

				})
			},
			fabClick() {
				// uni.showToast({
				// 	title: '点击了悬浮按钮',
				// 	icon: 'none'
				// })
				wx.navigateTo({
					url: '/pages/feedback/add'
				})
			},
			evaluateClick(e) {
				console.log(e)
				let url = '/pages/feedback/look?id=' + e.currentTarget.id
				wx.navigateTo({
					url: url
				})
			},
			bindClick(num,id) {
				console.log(id)
				if (num == 1) {
					this.request({
						'url': '/wx/syn/sign',
						'method': 'post',
						'data': {
							id:id,
							productId: this.$store.getters.productId,
							handleState:2
						}
					}).then(res => {
						console.log(res)
						if (res && res.code == 200) {
							// this.list = res.info
							// this.valiFormData.productModel = res.info.model
							uni.showToast({
								title: '确认成功'
							})
							this.getData()
						}
					}).catch(err => {
						this.submitDisabled = false
					})
				}
				if (num == 2) {
					let url = '/pages/feedback/handle?id=' + id
					wx.navigateTo({
						url: url
					})
				}
				if (num == 3) {
					let url = '/pages/feedback/evaluate?id=' + id
					wx.navigateTo({
						url: url
					})
				}
				if (num == 4) {
					let url = '/pages/feedback/look?id=' + id
					wx.navigateTo({
						url: url
					})
				}

			},
		}

	}
</script>

<style>
	.uni-table {
		/* width: 100%!important; */
		min-width: auto !important;
		font-size: 14px;
	}

	.container {
		padding: 15px;
	}

	.item {
		/* padding: 10px; */
		box-shadow: 0px 0px 10px #e2e2e2;
		margin-bottom: 10px;
		border-radius: 10px;
	}

	.name,
	.time,
	.user {
		display: flex;
		justify-content: space-between;
		line-height: 30px;
		font-size: 14px;
	}

	.right {
		color: #999;
	}

	.name .left,
	.time .left {
		min-width: 80px;
	}

	.item button {
		border-radius: 0!important;
		border: 0;
	}
	.item button::after{
		border-radius: 0!important;
		border: 0;
	}
</style>